package cn.mikuhl.onlinereviewsplatform.Controller;

import cn.mikuhl.onlinereviewsplatform.DTO.CommentDTO;
import cn.mikuhl.onlinereviewsplatform.Entities.Comment;
import cn.mikuhl.onlinereviewsplatform.Services.MovieService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class CommentController {

    @Autowired
    private MovieService movieService;

    @PostMapping("/movies/{movieId}/comments")
    public ResponseEntity<CommentDTO> submitComment(@PathVariable Long movieId,
                                                    @Valid @RequestBody Comment comment) {
        CommentDTO savedCommentDTO = movieService.submitComment(movieId, comment);
        return ResponseEntity.status(HttpStatus.CREATED).body(savedCommentDTO);
    }
}
